#include <iostream>
using namespace std;
const int inf=0x7fffffff;


bool check(int mid,int n,int m,int *a,int *b){
	int suma=0,sumb=0;
	for(int i=0;i<n;i++)
		if(a[i] <= mid)
			suma++;
	for(int i=0;i<m;i++)
		if(b[i] >= mid)
			sumb++;
	return suma>=sumb;
}


int main(){
	int n,m;
	cin>>n>>m;
	int a[n],b[m];
	int l=inf,r=inf+1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		l = min(l,a[i]);
	}
	for(int i=0;i<m;i++){
		cin>>b[i];
		r = max(r,b[i]);
	}
	
	
	while(r-l > 1){
		int mid=(r+l)/2;
		if(check(mid,n,m,a,b))
			r = mid;
		else
			l = mid;
//		cout<<l<<" "<<mid<<" "<<r<<endl;
	}
	
	
	if(l > r)
		cout<<r+1;
	else if(l == r){
		if(check(l,n,m,a,b))
			cout<<l;
		else
			cout<<l+1;
	}
	else if(check(l,n,m,a,b))
		cout<<l;
	else
		cout<<r;
	return 0;
}
